/*Timer Module*/
/*Interrupt driven*/

/*Required Header Files*/
#include <pic18.h>

/*Timer header file*/
#include "timer.h"

/*Global Variable definition*/
tTimerData timer;

/*Methods*/
/*Timer Module Initialization*/
void vTimerIntInit( unsigned int value )
{
	/*Clear the time count then setup timer. */
	TMR1H = TMR1L = 0;

    /*Set Timer Data*/
    timer.ticks = 0;
    timer.status.overflow = FALSE;

    /* Set the compare match value. */
	CCPR1L = (unsigned char)(value & (unsigned int) 0xFF);
	CCPR1H = (unsigned char)(((unsigned int)value >> 8) & (unsigned int ) 0xFF );

    /*Configure CCP compare mode*/
    CCP1M0 = CCP1M1 = CCP1M3 = ON;
    CCP1M2 = OFF;
    
    /*Set up High interrupt priority*/
    CCP1IP = HIGH;
    
    /*Set Up timer 1*/
    T1RD16 = ON;
    TMR1CS = INTERNAL;
    T1CKPS0 = T1CKPS1 = OFF;
    T1OSCEN = OFF;
    T3CCP2 = OFF; T3CCP1 = ON;
    TMR1ON = ON;
    
    /*Configure External tick generation*/   
    vTimerDirection(TIMER_CLOCK_PORT_IO, OUT);
    vTimerLevel(TIMER_CLOCK_PORT, LOW);    

    /*Enable CCP1 Interrupts*/
    CCP1IE = ON;
}
